package org.jeecg.modules.rental.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.aspect.annotation.PermissionData;
import org.jeecg.common.model.EnumDictOption;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.rental.entity.RentalCouponWriteoff;
import org.jeecg.modules.rental.entity.RentalPackageLevel;
import org.jeecg.modules.rental.service.IRentalPackageLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * @Description: 套餐级别
 * @Author: sean
 * @Date: 2024-06-05
 * @Version: V1.0
 */
@Api(tags = "套餐级别")
@RestController
@RequestMapping("/rental/package-level")
@Slf4j
public class RentalPackageLevelController extends JeecgController<RentalPackageLevel, IRentalPackageLevelService> {

	@Autowired
    private IRentalPackageLevelService rentalPackageLevelService;


    /**
     * 分页列表查询
     *
     * @param rentalPackageLevel
     * @param pageNo
     * @param pageSize
     * @return
     */
    //@AutoLog(value = "租车套餐级别-分页列表查询")
    @ApiOperation(value = "租车套餐级别-分页列表查询", notes = "租车套餐级别-分页列表查询")
    @GetMapping(value = "/list")
    @PermissionData(pageComponent="rental/package/levellist")
    public Result<IPage<RentalPackageLevel>> queryPageList(RentalPackageLevel rentalPackageLevel,
                                                           @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                           @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                           HttpServletRequest request) {
        QueryWrapper<RentalPackageLevel> queryWrapper = QueryGenerator.initQueryWrapper(rentalPackageLevel, request.getParameterMap());
        Page<RentalPackageLevel> page = new Page<RentalPackageLevel>(pageNo, pageSize);
        IPage<RentalPackageLevel> pageList = rentalPackageLevelService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    /**
     * 分页列表查询
     *
     * @return
     */
    @ApiOperation(value = "套餐级别-拉下选项", notes = "套餐级别-拉下选项")
    @GetMapping(value = "/options")
    public Result<List<EnumDictOption>> options() {
        List<EnumDictOption> optionList = rentalPackageLevelService.selectOptions();
        return Result.OK(optionList);
    }

    /**
     * 添加
     *
     * @param rentalPackageLevel
     * @return
     */
    @AutoLog(value = "租车套餐级别-添加")
    @ApiOperation(value = "租车套餐级别-添加", notes = "租车套餐级别-添加")
    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody RentalPackageLevel rentalPackageLevel) {
        rentalPackageLevelService.save(rentalPackageLevel);
        return Result.OK("common.add.success");
    }

    /**
     * 编辑
     *
     * @param rentalPackageLevel
     * @return
     */
    @AutoLog(value = "租车套餐级别-编辑")
    @ApiOperation(value = "租车套餐级别-编辑", notes = "租车套餐级别-编辑")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> edit(@RequestBody RentalPackageLevel rentalPackageLevel) {
        rentalPackageLevelService.updateById(rentalPackageLevel);
        return Result.OK("common.edit.success");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "租车套餐级别-通过id删除")
    @ApiOperation(value = "租车套餐级别-通过id删除", notes = "租车套餐级别-通过id删除")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
        rentalPackageLevelService.removeById(id);
        return Result.OK("common.delete.success");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "租车套餐级别-批量删除")
    @ApiOperation(value = "租车套餐级别-批量删除", notes = "租车套餐级别-批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.rentalPackageLevelService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("common.delete.batch.success");
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "租车套餐级别-通过id查询")
    @ApiOperation(value = "租车套餐级别-通过id查询", notes = "租车套餐级别-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<RentalPackageLevel> queryById(@RequestParam(name = "id", required = true) String id) {
        RentalPackageLevel rentalPackageLevel = rentalPackageLevelService.getById(id);
        if (rentalPackageLevel == null) {
            return Result.error("common.query.not.found", null);
        }
        return Result.OK(rentalPackageLevel);
    }

    /**
     * 导出excel
     *
     * @param request
     * @param rentalPackageLevel
     */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, RentalPackageLevel rentalPackageLevel) {
        return super.exportXls(request, rentalPackageLevel, RentalPackageLevel.class, "租车套餐级别");
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, RentalPackageLevel.class);
    }

}
